package com.example.javaee_library.Controller;/**
 * @author Miao-yongzheng
 * @create 2021-12-23 13:37
 */

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.example.javaee_library.Entity.User;
import com.example.javaee_library.Entity.action;
import com.example.javaee_library.Service.Appoint_Service;
import com.example.javaee_library.dto.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: 34911
 * @time: 2021/12/23 13:37
 */
@Controller
@RequestMapping("/Customer/Admin_operation")
public class Admin_operation {
    @Autowired
    Appoint_Service appoint_service;
    @RequestMapping(value = "/listaction", method = RequestMethod.GET)
    public ModelAndView listaciton(ModelAndView model, @RequestParam("UserId") String UserId) {
        List<action> list = appoint_service.findAll(UserId);
        list.forEach(item->{
            Date newDate = DateUtil.offset(item.getAppoint_Time(), DateField.DAY_OF_WEEK, 14);
            System.out.println(newDate);
            item.setBack_Time(newDate);
        });
        model.addObject("list", list);
        model.setViewName("listOperation");
        // list.jsp + model = ModelAndView
        return model;// WEB-INF/jsp/"list".jsp
    }
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public JsonData deleteaciton( @RequestParam("Id") String Id) {
        System.out.println(Id);
        int back = appoint_service.delete(Id);
        if(back>=0)
            return JsonData.buildSuccess(Id+"删除成功");
        return JsonData.buildError(Id+"删除失败");// WEB-INF/jsp/"list".jsp
    }
}
